package com.ucar.umock.client.exector.support;

import com.ucar.umock.client.UMockHelper;
import com.ucar.umock.client.dto.UMockMethodRuntimeInfoDTO;
import com.ucar.umock.client.config.UMockMethodConfigBean;
import com.ucar.umock.client.enums.EnumMockExectorType;
import com.ucar.umock.client.exector.UMockValueCustomHandle;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;

/**
 * @ClassName UMockValueCustomHandle
 * @Description TODO
 * @Author zhanbs baoshan.zhan@ucarinc.com
 * @Date 2020/4/3 15:49
 * @Version 1.0
 **/
@Component
public class UMockValueCustomExector extends UMockValueBaseExector {
    public Object exec(UMockMethodConfigBean config, UMockMethodRuntimeInfoDTO methodRuntimeDTO) {
        String customHandle=config.getCustomHandle();
        Assert.notNull(customHandle,"自定义处理Handle 不为空");
        UMockValueCustomHandle handle=UMockHelper.getBean(customHandle);
        Object valObj=handle.handle(methodRuntimeDTO);
        return valObj;
    }

    public EnumMockExectorType getType() {
        return EnumMockExectorType.CUSTOM_HANDLE;
    }
}
